﻿// inputbox.cpp: 实现文件
//

#include "stdafx.h"
#include "MFCApplication4.h"
#include "inputbox.h"
#include "afxdialogex.h"


// inputbox 对话框

IMPLEMENT_DYNAMIC(inputbox, CDialogEx)

inputbox::inputbox(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_Inputbox, pParent)
{

}

inputbox::~inputbox()
{
}

void inputbox::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, comboboxCC);
	for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
	{
		if (it->getUsername() == SystemALL.usernow)
		{
			for (int l = 0; l < it->MyAccount.size(); l++)
			{
				if (it->MyAccount[l]->getType() == this->typetoop)
				{
					string addt = it->MyAccount[l]->getID();
					CString bc(addt.c_str());
					comboboxCC.AddString(bc);
				}
			}
		}
	}
	
}


BEGIN_MESSAGE_MAP(inputbox, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON5, &inputbox::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON4, &inputbox::OnBnClickedButton4)
END_MESSAGE_MAP()


// inputbox 消息处理程序


void inputbox::OnBnClickedButton5()
{
	int check = 0;
	vector<string> args;
	string moneys, infos;
	CString moneyc, infoc;
	GetDlgItemText(IDC_EDIT1, moneyc);
	GetDlgItemText(IDC_EDIT3, infoc);
	moneys = CT2A(moneyc.GetString());
	infos = CT2A(infoc.GetString());
	string opnumber="0";
	string indexnumber = "0";
	if (this->toop == "d")
		opnumber = "100";
	else if (this->toop == "w")
		opnumber = "119";
	CString strCBText;
	comboboxCC.GetWindowText(strCBText);
	string idaccout= CT2A(strCBText.GetString());
	for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
	{
		if (it->getUsername() == SystemALL.usernow)
		{
			for (int l = 0; l < it->MyAccount.size(); l++)
			{
				if (it->MyAccount[l]->getID() == idaccout)
				{
					indexnumber = to_string(l);
					check = 1;
				}
			}
		}
	}
	if (infos == "")
		check = 0;
	if (check ==0)
		::MessageBox(NULL, _T("发生错误，可能是您的数据填写有误。"), _T("提示"), MB_ICONWARNING);
	else if(check == 1)
	{
		args.push_back(opnumber);
		args.push_back(indexnumber);
		args.push_back(moneys);
		args.push_back(infos);

		for (vector<Controller>::iterator it = SystemALL.Center.begin(); it != SystemALL.Center.end(); it++)
		{
			if (it->getUsername() == SystemALL.usernow)
			{
				try {
					SystemALL.nDate = it->getCommand(args, SystemALL.nDate);
				}
				catch (runtime_error &e)
				{
					string tmp = e.what();
					tmp += "\r\n";
					SystemALL.WriteIntoEditer(tmp);
					check = 2;
				}
			}
		}
	}

	if (check == 2)
	{
		//::MessageBox(NULL, _T("发生了难以预料的未知错误"), _T("提示"), MB_ICONWARNING);
	}
}


void inputbox::OnBnClickedButton4()
{
	EndDialog(0);
	// TODO: 在此添加控件通知处理程序代码
}
